package com.shibm.eureka.provider;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class TestController {

	@Autowired
	private DiscoveryClient client;
	
	@GetMapping(value = "/test")
	public String test() {
		List<ServiceInstance> serviceInstance=client.getInstances("provider");
		if(CollectionUtils.isEmpty(serviceInstance)) {
			return "none";
		}
		for(ServiceInstance obj: serviceInstance) {
			log.info("host:{},id={}",obj.getHost(),obj.getInstanceId());
		}
		return "test";
	}
}
